﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Resources;

using EHTWebsite.Code;

namespace EHTWebsiteProject
{
    public partial class KhachHangs : System.Web.UI.Page
    {
        public Boolean IsVN = true;
        private String languageCode = "vi-VN";
        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

        private Int32 pageIndex = 1;
        private Int32 pageSize = 12;
        private Int32 totalRecord = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                languageCode = Session[HangSo.LANGUAGE_CODE].ToString();

                if (languageCode == "en-us")
                {
                    IsVN = false;
                }

            }
            catch (Exception ex)
            {
            }

            try
            {
                pageIndex = Int32.Parse(Request.QueryString["PageIndex"].ToString());
            }
            catch (Exception ex)
            {
            }

            if (!Page.IsPostBack)
            {
             
                KhachHang theKhachHang = new KhachHang();
                theKhachHang.KhachHangID = -1;
                theKhachHang.DiaChiOther = "";
                theKhachHang.DiaChiVN = "";
                theKhachHang.DiDong = "";
                theKhachHang.DienThoai = "";
                theKhachHang.Email = "";
                theKhachHang.GhiChuOther = "";
                theKhachHang.GhichuVN = "";
                theKhachHang.TenKhachHangOther = "";
                theKhachHang.TenKhachHangVN = "";

                pageSize = this.PaggingControl1.PageSize;

                this.rpKhachHangs.DataSource = KhachHangProvider.GetKhachHangsByFillter(theKhachHang, pageIndex, pageSize, out totalRecord);
                this.rpKhachHangs.DataBind();

                this.PaggingControl1.TotalRecord = totalRecord;
                this.PaggingControl1.PageURL = "/khach-hang.aspx";

                Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
                LoadLanguage(Thread.CurrentThread.CurrentCulture);
            }
        }

        public void LoadLanguage(CultureInfo ci)
        {
            this.ltrKhachHang_Title.Text = rm.GetString("ltrKhacHang_Title", ci);
        }

        public String FormatStringForUrl(String input)
        {
            return HelpMethod.FormatStringForUrl(input);
        }

        private String CatString(String input)
        {
            return HelpMethod.CatString(input, 25);
        }
    }
}